﻿/*
 * 9073194
 */
$(function () {
    init();
});

function init() {
    helper.markCurrentPage();
}

//删除提示
function del(url) {
    art.dialog.confirm('你确定要删除吗？', function () {
        window.location.href = url;
    }, function () { });
}

//添加。修改分类
/**
 * url----地址
 * param---参数
 * title---弹框标题
 */
function openCategory(url, param, title) {
    art.dialog.open(url + param, {
        title: title,
        lock: true,
        ok: function () {
            var iframe = this.iframe.contentWindow;
            if (!iframe.document.body) {
                alert('iframe还没加载完毕呢')
                return false;
            };
            var form = iframe.document.getElementById("categoryForm"),
                CategoryName = iframe.document.getElementById('CategoryName'),
                CategoryFlag = iframe.document.getElementById('CategoryFlag');
            if (check(CategoryName) && check(CategoryFlag)) {
                //提交表单
                $.ajax({
                    url: url,
                    type: 'post',
                    dataType: 'text',
                    data: $(form).serialize(),
                    success: function (data) {
                        var json = jQuery.parseJSON(data);
                        if (json.status == 'y') {
                            art.dialog({
                                time: 3,
                                icon: 'succeed',
                                id: 'callTips',
                                title: false,
                                cancel: false,
                                fixed: true,
                                lock: true,
                                content: json.msg,
                                close: function () { art.dialog.opener.window.location.href = '/sean/categorys' }
                            });
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown)
                    { art.dialog.tips(textStatus); }
                });
            };
            return false;
        },
        cancel: true
    });

    // 表单验证
    var check = function (input) {
        if (input.value === '') {
            var $inputParent = $(input).parent().parent(".form-group").addClass("check-error")
            input.focus();
            return false;
        } else {
            return true;
        };
    };
}